package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.BpDeviceFacilityDetectRecord;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;

/**
 * @Author ZhangDong
 * @Date 2021/1/12 15:24
 */
public interface BpDeviceFacilityDetectRecordDao extends JpaRepository<BpDeviceFacilityDetectRecord, Long> {

    Page<BpDeviceFacilityDetectRecord> findByDeviceFacilityId(Long deviceFacilityId, Pageable pageable);

    @Query(value = "select count(*) from wwyt_bp_device_facility_detect_record where id != ?1 and device_facility_id = ?2 and detect_date >= ?3 and delete_flag = '0' ",nativeQuery = true)
    Long isLastRecord(Long id, Long deviceFacilityId, Date detectDate);
}
